package com.xidian.zhiancloud.service.cgs.TrainManager;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xidian.zhiancloud.dao.TrainTypeMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.Information;
import com.xidian.zhiancloud.model.TrainType;
import com.xidian.zhiancloud.model.TrainTypeExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.xidian.zhiancloud.util.tools.ObjectUtil.isEmpty;

/**
 * @Author chenguosong
 * @Date 2020/11/24 17:25
 * @Mail 2581592671@qq.com
 */
@Service
public class TrainTypeService {
    @Autowired
    private TrainTypeMapper trainTypeMapper;

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    public void add(TrainType trainType) {
        if(!isEmpty(trainType)){
            trainTypeMapper.insert(trainType);
        }else{
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    public void deletebyid(Long id) {
        trainTypeMapper.deleteByPrimaryKey(id);
    }

    public Page<TrainType> getListPlan(TrainType trainType) {
    	PageHelper.startPage(trainType.getPageNum(), trainType.getPageSize());
    	Page<TrainType> pagedata =trainTypeMapper.getListPlan(trainType);
        return pagedata;
    }

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    public void update(TrainType trainType) {
        if(!isEmpty(trainType)){
            trainTypeMapper.updateByPrimaryKeySelective(trainType);
        }else{
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }

	public void deleteTypeByIds(Long[] ids) {
		// TODO Auto-generated method stub
		trainTypeMapper.deleteTypeByIds(ids);
	}
}
